package Game.Objects;

import org.newdawn.slick.Input;
import org.newdawn.slick.geom.Vector2f;

import Game.GameHelper;
import Game.Level;

/** Camera 
 * @author Aikidos
 */
public class GOCamera extends GameObject {

	/** Offset */
	private Vector2f _offset;
	
	/** Control move speed */
	private float _moveSpeed = 0.3f;
	
	/** Control is locked? */
	private boolean _isLocked = false;
	
	public GOCamera(ObjectManager objectManager) {
		super(objectManager, "Camera");
		
		Position = new Vector2f();
		
		// Set offset
		_offset = new Vector2f(GameHelper.getGame().getWidth() / 2,
				GameHelper.getGame().getHeight() / 2);
	}
	
	/** Returns offset for correct draw game objects
	 * @return Offset for correct draw game objects
	 */
	public Vector2f getDrawOffset() {
		return new Vector2f(Position.x - _offset.x,
				Position.y - _offset.y);
	}

	/** Look at object
	 * @param gameObject - Game object
	 */
	public void lookAt(GameObject gameObject) {
		Position.set(gameObject.Position);
	}
	
	/** Lock control */
	public void lock() {
		_isLocked = true;
	}
	
	/** Unlock control */
	public void unlock() {
		_isLocked = false;
	}
	
	@Override
	public void update(int delta) {
		if (!_isLocked) {
			Input input = GameHelper.getGame().getInput();
			if (input.isKeyDown(Input.KEY_LEFT))
				Position.x -= _moveSpeed * delta;
			if (input.isKeyDown(Input.KEY_UP))
				Position.y -= _moveSpeed * delta;
			if (input.isKeyDown(Input.KEY_RIGHT))
				Position.x += _moveSpeed * delta;
			if (input.isKeyDown(Input.KEY_DOWN))
				Position.y += _moveSpeed * delta;
		}
	}
	
	@Override
	public void step() {
		// Set camera position to player position
		lookAt(_objectManager.getPlayer());
	}
}
